#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 2e5 + 10;

int a[N],m,n,ans;

bool check(int x) {
	ans = 0;
	for(int i = 1;i <= x;i++) ans = max(ans,(a[i] + a[x * 2 - i + 1]) % m);
	for(int i = 1;i <= n - x;i++) {
		int res = a[2 * x + i] + a[n * 2 - i + 1];
		if(res < m) return 0; ans = max(ans,res - m); 
	}
	return 1;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in; m = in;
	for(int i = 1;i <= 2 * n;i++) a[i] = in; sort(a + 1,a + n * 2 + 1);
	int l = 0,r = n;
	while(l <= r) {
		int mid = l + r >> 1;
		if(check(mid)) r = mid - 1;
		else l = mid + 1;
	}
	check(l); printf("%d\n",ans);
	return 0;
}
